﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Networking;
public class CameraFollow : NetworkBehaviour
{
    Vector3 target;
    //相机移动速度
    int speed = 70;
    float temp;
    bool flag;

    bool check()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            flag = false;
            return flag;
        }
        else
        {
            flag = true;
            return flag;
        }
    }

    void LateUpdate()
    {
        if (isLocalPlayer == false)//isLocalPlayer用于判断是否是当前客户端进行操作，以防止误操作别人的角色
        {
            return;//如果不是当前对象，则不执行下述代码
        }

        if (Input.GetMouseButton(0))
        {
            if (Input.GetMouseButtonDown(0))
            {
                check();
            }
            if (flag != false)
            {
                float x;
                float y;
                x = Input.GetAxis("Mouse X");
                y = Input.GetAxis("Mouse Y");
                //if (this.transform.position.z + y > 300)
                //{
                //    Vector3 tempPos = transform.transform.position;
                //    tempPos.z = 300;
                //    transform.transform.position = tempPos;
                //}
                target = new Vector3(-x, 0, -y);
                transform.Translate(target * Time.deltaTime * speed, Space.World);
            }

        }
    }
}